package com.xitang.system.poi;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.xitang.common.bean.BizMaterial;
import com.xitang.common.mapper.BizMaterialMapper;

import java.util.Map;

public class BizMaterialExcelListener extends AnalysisEventListener<BizMaterial> {

    private BizMaterialMapper materialMapper;

    public BizMaterialExcelListener(BizMaterialMapper materialMapper) {
        this.materialMapper = materialMapper;
    }

    // 逐行读取excel内容
    @Override
    public void invoke(BizMaterial material, AnalysisContext analysisContext) {
        System.out.println("excel内容：" + material);
        materialMapper.insert(material);
    }

    // 读取excel表头信息
    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        System.out.println("表头：" + headMap);
    }

    // 读取完之后执行
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println("end");
    }
}
